package com.csair.youth.dao.impl.hibernate3;

import java.util.ArrayList;
import java.util.List;

import com.csair.youth.database.Notice;
import com.csair.youth.database.User;
import common.util.PagingAndSorting;

/**
 * Impl:auto created by daobuilder1.1.1 
 * @version 1.0
 * @author daobuilder@csair.com
 */
public class NoticeDaoImpl extends com.csair.youth.dao.impl.hibernate3.base.NoticeDaoImplBase{
	private static final String HQL_SHOW_LATEST_NOTICE = "select a, b."+User.PROP_NAME+" from "+Notice.REF+" a, "+User.REF+" b where a."+Notice.PROP_PUBLISH_USER_ID+"=b."+User.PROP_ID;
	
	public List<Notice> showLatestNotices(int count){
		PagingAndSorting ps = new PagingAndSorting("a.LastModifyTime", true);
		ps.setFirstResult(0);
		ps.setMaxResults(count);
		List ret = this.getGenericDao().find(HQL_SHOW_LATEST_NOTICE, ps);
		if(ret == null || ret.size() == 0){
			return ret;
		}
		List<Notice> ret2 = new ArrayList<Notice>();
		for(int i=0; i<ret.size(); i++){
			Notice xx = cast1(ret.get(i));
			ret2.add(xx);
		}
		return ret2;
	}
	
	private Notice cast1(Object xx){
		Object[] xxx = (Object[])xx;
		Notice notice = (Notice)xxx[0];
		String userName = (String)xxx[1];
		notice.setPublishUserId(userName);
		return notice;
	}
}